package org.jeecg.modules.xl.api;

import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.common.api.vo.Result;
import org.jeecg.config.shiro.IgnoreAuth;
import org.jeecg.modules.xl.api.dto.ProductVO;
import org.jeecg.modules.xl.kuaimai.entity.XlKuaimaiStock;
import org.jeecg.modules.xl.kuaimai.service.IXlKmStockService;
import org.jeecg.modules.xl.order.service.IXlCustomerOrdeService;
import org.jeecg.modules.xl.product.entity.XlProductInfo;
import org.jeecg.modules.xl.product.service.IXlProductInfoService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.*;

/**
* 退货退款售后单主表(xl_customer_as)表控制层
*
* @author xxxxx
*/
@RestController
@RequestMapping("/edi")
public class SLTEDI {

    @Resource
    private IXlProductInfoService xlProductInfoService;

    @Resource
    private IXlKmStockService xlKmStockService;


    @Resource
    private IXlCustomerOrdeService xlCustomerOrdeService;

    @IgnoreAuth
    @GetMapping(value = "/gljroute")
    public Result<?> gaolujieRoute( @RequestParam(required = true) String route,  @RequestParam(required = true) String sid ,@RequestParam (required = true) String spassword,  @RequestParam (required = false) int month){
        if(!("glj".equals(sid)&&"UHUFRtz4vzjx0GeUjnq6kc1vuwYMTEOg".equals(spassword))){
            return Result.error("cid或者 cpassword 错误");
        }
        if("product".equals(route)){//产品
            QueryWrapper<XlProductInfo> queryWrapper = new QueryWrapper<XlProductInfo>();
            queryWrapper.eq("brand","高露洁");
            List<XlProductInfo> productInfos = xlProductInfoService.list(queryWrapper);
            List<ProductVO> resultList  = new ArrayList<>();
            for(XlProductInfo xlProductInfo : productInfos){
                ProductVO productVO = new ProductVO();
                productVO.setUpcCode(xlProductInfo.getUpcCode());
                productVO.setProductName(xlProductInfo.getProductName());
                productVO.setCartonSpec(xlProductInfo.getCartonSpec());
                productVO.setProductSpec(xlProductInfo.getProductSpec());
                resultList.add(productVO);
            }
            return Result.ok(resultList);
        }
        if("solist".equals(route)){//销售
            if(!ObjectUtil.isAllNotEmpty(month)){
                return Result.error("month不能为空");
            }
            return Result.ok(xlCustomerOrdeService.queryBrandOfOrderDetail("高露洁",month));
        }
        if("polist".equals(route)){//采购
            return Result.ok("http://www.baidu.com");
        }
        if("stock".equals(route)) {//库存
            return Result.ok(xlKmStockService.getBrandofStockList("高露洁"));
        }
        return Result.error("接口不存在或者你无权限");
    }

}
